﻿
function Add-TypeFromFile {
    [CmdletBinding(DefaultParameterSetName = "Path")]
    Param(
        [Parameter(Position = 0, ParameterSetName = "Path", Mandatory = $true)]
        [string[]] $Path,
        
        [Parameter(ParameterSetName = "LiteralPath", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [Alias("FullName")]
        [string[]] $LiteralPath
    )

    Process {

        foreach($curPath in ($LiteralPath + $Path | Where {$_} | Resolve-Path)) {
            if(Test-Path $curPath -PathType Leaf) {
                Write-Verbose "Adding types from '$curPath'."
                Add-Type -Path $curPath
            }
        }
    }
}

function Add-FormatData {
    [CmdletBinding(DefaultParameterSetName = "Path")]
    Param(
        [Parameter(Position = 0, ParameterSetName = "Path", Mandatory = $true)]
        [string[]] $Path,
        
        [Parameter(ParameterSetName = "LiteralPath", Mandatory = $true, ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
        [Alias("FullName")]
        [string[]] $LiteralPath
    )

    Process {

        foreach($curPath in ($LiteralPath + $Path | Where {$_} | Resolve-Path)) {
            if(Test-Path $curPath -PathType Leaf) {

                Write-Verbose "Adding Format data from '$curPath'."
                Update-FormatData -PrependPath $curPath
            }
        }
    }
}

Add-TypeFromFile $PSScriptRoot\*.cs
Add-FormatData   $PSScriptRoot\*.ps1xml
